#include "tcpserver.hpp"
#include "command.hpp"

std::string defaultfunc(const std::string &word, InetAddr &addr)
{
    LOG(LogLevel::DEBUG) << "defaultfunc";
    return "hello " + word;
}

void Usage(const std::string proc)
{
    std::cerr << "Usage:" << proc << " port" << std::endl;
}

// 远程命令执行
int main(int args, char* argv[])
{
    if(args != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }

    Enable_Console_Log_Strategy();

    // 字典对象
    // Dict d;
    // d.LoadDict();

    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port, defaultfunc);

    // std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port, [&d](const std::string &word, InetAddr &addr){
    //     return d.Translate(word, addr);
    // });

    // Command cmd;

    // func_t f = std::bind(&Command::Excute, &cmd, std::placeholders::_1, std::placeholders::_2);

    // // std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port, f);
    // std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port, [&cmd](const std::string &command, InetAddr &addr){
    //     return cmd.Excute(command, addr);
    // });

    tsvr->Init();
    tsvr->Run();
    return 0;
}